<?php
/**
    * Dynamically add region to the currently set template
    *
    * @access  public
    * @param   string   Name to identify the region
    * @param   array  Optional array with region defaults
    * @param   string Optional string region name to deposit this new region before in stack
    * @return  void
    */
   
   function add_region($name, $props = array(), $before = null)
   {
      if ( ! is_array($props))
      {
         $props = array();
      }
      if ( ! isset($this->regions[$name]))
      {
          if ( $before === null)
          {
             $this->regions[$name] = $props;
          }
          else
          {
             $pos = array_search($before,array_keys($this->regions));
             $this->regions = array_merge(array_slice($this->regions,0,$pos), array( $name => $props ), array_slice($this->regions,$pos));
          }
      }
      else
      {
         show_error('The "'. $name .'" region has already been defined.');
      }
   } 